//
//  WBNavigationController.swift
//  SwiftWeibo
//
//  Created by Lausen on 2017/4/7.
//  Copyright © 2017年 id. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationBar.isHidden = true
    }
    
    //重写nav的push方法,隐藏tabbar
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0{
            
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? WBBaseViewController{
                
                var title = "返回"
                
                if childViewControllers.count == 1 {
                    
                    title = childViewControllers.first?.title ?? title
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent),isBack: true)
            }
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    
    @objc private func popToParent(){
        
        popViewController(animated: true)
    }
}
